/**
 * 初始化考试信息详情对话框
 */
var SeniorExamineeInfoDlg = {
    seniorExamineeInfoData: {},
    validateFields: {
        seniorSchoolId: {
            trigger: "change",
            validators: {
                notEmpty: {
                    message: '请选择所属学校'
                }
            }
        },
        seniorClassId: {
            trigger: "change",
            validators: {
                notEmpty: {
                    message: '请选择所属班级'
                }
            }
        },
        examCardNumber: {
            validators: {
                notEmpty: {
                    message: '请输入准考证号'
                },
                stringLength: {
                    max: 50,
                    message: '准考证号长度不能超过50'
                }
            }
        },
        birthday :{
            validators: {
                notEmpty: {
                    message: '请输入出生年月'
                }
            }
        },
        studentName: {
            validators: {
                notEmpty: {
                    message: '请输入考生姓名'
                },
                stringLength: {
                    max: 100,
                    message: '考生姓名长度不能超过100'
                }
            }
        },
        idCard: {
            validators: {
                notEmpty: {
                    message: '请输入身份证号码'
                },
                id: {
                    country: 'CN',
                    message: '请输入正确的身份证号码'
                }
            }
        },
        archivesNumber: {
            validators: {
                notEmpty: {
                    message: '建档号不能为空'
                },
                stringLength: {
                    max: 50,
                    message: '建档号长度不能超过50'
                }
            }
        },
        phone1: {
            validators: {
                phone: {
                    country: 'CN',
                    message: '请输入正确的联系方式'
                }
            }
        },
        phone2: {
            validators: {
                phone: {
                    country: 'CN',
                    message: '请输入正确的联系方式'
                }
            }
        },
        examSiteNumber: {
            validators: {
                stringLength: {
                    max: 100,
                    message: '考场号长度不能超过100'
                }
            }
        },
        residenceAreaCode: {
            validators: {
                stringLength: {
                    max: 20,
                    message: '户籍地区代码长度不能超过20'
                }
            }
        },
        seatNumber: {
            validators: {
                stringLength: {
                    max: 100,
                    message: '座位号长度不能超过100'
                }
            }
        },
        residenceAddress: {
            validators: {
                stringLength: {
                    max: 100,
                    message: '户籍地址长度不能超过100'
                }
            }
        },
        studentNumber: {
            validators: {
                stringLength: {
                    max: 50,
                    message: '学籍号长度不能超过50'
                }
            }
        },
        nation: {
            validators: {
                stringLength: {
                    max: 50,
                    message: '民族长度不能超过50'
                }
            }
        },
        nativePlace: {
            validators: {
                stringLength: {
                    max: 50,
                    message: '籍贯长度不能超过50'
                }
            }
        },
        politicalName: {
            validators: {
                stringLength: {
                    max: 50,
                    message: '政治面貌长度不能超过50'
                }
            }
        },
        studentTypeName: {
            validators: {
                stringLength: {
                    max: 50,
                    message: '考生类型名称长度不能超过50'
                }
            }
        },
    }
};

/**
 * 清除数据
 */
SeniorExamineeInfoDlg.clearData = function () {
    this.seniorExamineeInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key
 *            数据的名称
 * @param val
 *            数据的具体值
 */
SeniorExamineeInfoDlg.set = function (key, val) {
    this.seniorExamineeInfoData[key] = (typeof val == "undefined") ? $(
        "#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key
 *            数据的名称
 * @param val
 *            数据的具体值
 */
SeniorExamineeInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
SeniorExamineeInfoDlg.close = function () {
    parent.layer.close(window.parent.SeniorExaminee.layerIndex);
}

/**
 * 收集数据
 */
SeniorExamineeInfoDlg.collectData = function () {
    this.set('id').set('examCardNumber').set('examSiteNumber').set('seniorSchoolId').set('seniorClassId')
        .set('seatNumber').set('studentName').set('gender').set('birthday', $("#birthday").val() == "" ? "" : $("#birthday").val() + " 00:00:00")
        .set('nation').set('nativePlace').set('politicalName').set('studentTypeName').set('idCard').set('phone1')
        .set('phone2').set('residenceAreaCode').set('residenceAddress')
        .set('studentNumber').set('archivesNumber').set('seniorSchoolCode')
        .set('seniorSchoolName').set('seniorClassCode').set(
        'seniorClassName').set('headerPath').set('writeStatus')
        .set('confirmStatus');
}

/**
 * 验证数据是否为空
 */
SeniorExamineeInfoDlg.validate = function () {
    $('#examineeInfoForm').data("bootstrapValidator").resetForm();
    $('#examineeInfoForm').bootstrapValidator('validate');
    return $("#examineeInfoForm").data('bootstrapValidator').isValid();
};

/**
 * 提交添加
 */
SeniorExamineeInfoDlg.addSubmit = function () {

    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    // 提交信息
    var ajax = new $ax(Feng.ctxPath + "/seniorExaminee/save", function (data) {
        Feng.success("添加成功!");
        window.parent.SeniorExaminee.table.refresh();
        SeniorExamineeInfoDlg.close();
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.seniorExamineeInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
SeniorExamineeInfoDlg.editSubmit = function () {

    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    // 提交信息
    var ajax = new $ax(Feng.ctxPath + "/seniorExaminee/save", function (data) {
        Feng.success("修改成功!");
        window.parent.SeniorExaminee.table.refresh();
        SeniorExamineeInfoDlg.close();
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.seniorExamineeInfoData);
    ajax.start();
}
/**
 * 获取shoolId
 */
SeniorExamineeInfoDlg.getSchoolId = function (schoolSelectId) {
    return {
        schoolId: $("#" + schoolSelectId).select2("val")
    }
}

$('#seniorSchoolId').on('select2:select', function (e) {
    $("#seniorClassId").val(null).trigger("change");
});


$(function () {
    Feng.initValidator("examineeInfoForm", SeniorExamineeInfoDlg.validateFields);
});
